//
//  SDSubCell.m
//  SDNestedTablesExample
//
//  Created by Daniele De Matteis on 21/05/2012.
//  Copyright (c) 2012 Daniele De Matteis. All rights reserved.
//

#import "SDSubCell.h"
#import "clsOtherFun.h"
@implementation SDSubCell

@synthesize parentTable;
@synthesize lbWaybill;
@synthesize cellIndex;
@synthesize lbOverdue;
@synthesize lbLwhl;
@synthesize lbTopay;
@synthesize lbAddress;
@synthesize lbFreight;
-(void)setSubData:(clsDifficult *)data
{
    if (!self.lbWaybill) {
        self.lbWaybill = [self creatLabel:301 :0 :35 :self.frame.size.width-140];
        [self addSubview:self.lbWaybill];
    }
    if (!self.lbTopay) {
        self.lbTopay = [self creatLabel:302 :0 :self.frame.size.width-95 :90];
        [self addSubview:self.lbTopay];
    }
    if (!self.lbLwhl) {
        self.lbLwhl = [self creatLabel:303 :20 :35 :self.frame.size.width-140];
        [self addSubview:self.lbLwhl];
    }
    if (!self.lbFreight) {
        self.lbFreight = [self creatLabel:304 :20 :self.frame.size.width-95 :90];
        [self addSubview:self.lbFreight];
    }
    self.lbWaybill.text=[NSString stringWithFormat:@"運單號：%@",data.Oid];
//    self.lbOverdue.text=@"";
    self.lbLwhl.text=[NSString stringWithFormat:@"長寬高：%@X%@X%@ CM",data.Long,data.Width,data.Height];
    self.lbTopay.text=[NSString stringWithFormat:@"到付費：%@元",data.DaoFu];
//    self.lbAddress.text=@"";
    self.lbFreight.text=[NSString stringWithFormat:@"運    費：%@元",data.Price];
}
-(void)setSubDataWithCate:(clsCategory *)data
{
    if (!self.lbWaybill) {
        self.lbWaybill = [self creatLabel:301 :0 :25 :ScreenWidth-130];
        [self addSubview:self.lbWaybill];
    }
    if (!self.lbOverdue) {
        self.lbOverdue = [self creatLabel:302 :0 :ScreenWidth-105 :100];
        [self addSubview:self.lbOverdue];
    }
    if (!self.lbLwhl) {
        self.lbLwhl = [self creatLabel:303 :20 :25 :ScreenWidth-130];
        [self addSubview:self.lbLwhl];
    }
    if (!self.lbTopay) {
        self.lbTopay = [self creatLabel:304 :20 :ScreenWidth-105 :100];
        [self addSubview:self.lbTopay];
    }
    if (!self.lbAddress) {
        self.lbAddress = [self creatLabel:305 :40 :13 :ScreenWidth-130];
        [self addSubview:self.lbAddress];
    }
    if (!self.lbFreight) {
        self.lbFreight = [self creatLabel:306 :40 :ScreenWidth - 105 :100];
        [self addSubview:self.lbFreight];
    }
    self.lbWaybill.text=[NSString stringWithFormat:@"運單號：%@",data.ExpressID];
    NSDateFormatter *format=[[NSDateFormatter alloc] init];
    [format setDateFormat:@"yyyy-MM-dd"];
    NSDate *fromdate=[format dateFromString:data.dqDate];
    NSInteger day=0;
    if (fromdate) {
        NSTimeZone *fromzone = [NSTimeZone systemTimeZone];
        NSInteger frominterval = [fromzone secondsFromGMTForDate: fromdate];
        NSDate *fromDate = [fromdate  dateByAddingTimeInterval: frominterval];
//        NSLog(@"fromdate=%@",fromDate);
        //获取当前时间
        NSDate *date1 = [NSDate date];
        NSTimeZone *zone = [NSTimeZone systemTimeZone];
        NSInteger interval = [zone secondsFromGMTForDate: date1];
        NSDate *localeDate = [date1  dateByAddingTimeInterval: interval];
//        NSLog(@"enddate=%@",localeDate);
        
        double intervalTime = [localeDate timeIntervalSinceReferenceDate] - [fromDate timeIntervalSinceReferenceDate];
        
        long lTime = (long)intervalTime;
        day = lTime/60/60/24;
    }
    
    float money = [clsOtherFun MathMoney:[data.Long floatValue] :[data.Width floatValue] :[data.Height floatValue] :day];
    self.lbOverdue.text=[NSString stringWithFormat:@"逾期費：%.0f",money];
    self.lbLwhl.text=[NSString stringWithFormat:@"長寬高：%@X%@X%@ CM",data.Long,data.Width,data.Height];
    self.lbTopay.text=[NSString stringWithFormat:@"到付費：%@元",data.daofu];
    self.lbAddress.text=[NSString stringWithFormat:@"取貨地址：%@",data.Oaddress];
    self.lbFreight.text=[NSString stringWithFormat:@"運    費：%@元",data.Price];
    if ([data.IsBig integerValue]==1) {
        for (UIView *view in self.subviews) {
            if ([view isKindOfClass:[UILabel class]]) {
                UILabel *label = (UILabel *)view;
                label.textColor = [UIColor whiteColor];
            }
        }
    }else{
        for (UIView *view in self.subviews) {
            if ([view isKindOfClass:[UILabel class]]) {
                UILabel *label = (UILabel *)view;
                label.textColor = [UIColor blackColor];
            }
        }
    }
}
- (UILabel *)creatLabel:(NSInteger)tag :(float)top :(float)x :(float)width
{
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(x, top, width, 21)];
    label.tag=tag;
    label.font=[UIFont systemFontOfSize:12];
    label.textAlignment = NSTextAlignmentLeft;
    label.textColor=[UIColor blackColor];
    return label;
}
@end
